# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=opencollada

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=987.8dc9e4e
pkgrel=1
pkgdesc="Stream based reader and writer library for COLLADA files (mingw-w64)"
arch=('any')
url="https://github.com/khronosGroup/OpenCOLLADA/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "${MINGW_PACKAGE_PREFIX}-cmake" "git")
depends=("${MINGW_PACKAGE_PREFIX}-libxml2"
    "${MINGW_PACKAGE_PREFIX}-pcre")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
options=('staticlibs' 'strip')
source=("${_realname}"::"git://github.com/KhronosGroup/OpenCOLLADA.git"
    fix-mingw-w64.patch)
md5sums=('SKIP'
         'd7c4b3a0c59eae4351b627d4eb714645')

pkgver() {
  cd "$srcdir/$_realname"
  printf "%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}/${_realname}"
  patch -p0 -i ${srcdir}/fix-mingw-w64.patch
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null
  
  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null
  
  mkdir -p "${srcdir}"/build-${MINGW_CHOST}
  cd "${srcdir}"/build-${MINGW_CHOST}
  ${MINGW_PREFIX}/bin/cmake.exe \
     -G"MSYS Makefiles" \
     -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
     -DCMAKE_BUILD_TYPE=RELEASE \
     ../${_realname}
  make
}

package() {
  cd "${srcdir}"/build-${MINGW_CHOST}
  make -j1 install
}
